define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    dragsort_url: '',
                    index_url: 'service/skill/skill/index' + location.search,
                    add_url: 'service/skill/skill/add',
                    edit_url: 'service/skill/skill/edit',

                    multi_url: 'service/skill/skill/multi',
                    import_url: 'service/skill/skill/import',
                    table: 'service_skill'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('服务者信息'),operate: false,formatter:function (value,row){
                            let result = `<div style="display: flex;">
        <img style="width: 100px;height: 100px;" src="${row.image}"/>
        <div style="margin-left: 16px;flex:1;">
            <div style="display: flex;align-items: center">
                <span  style="font-size: 16px;color: #333;">${row.name}</span>
                <div style="background: rgba(248, 118, 121, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: rgba(248, 118, 121, 1)">ID：${row.id}</div>
                <div style="background: rgba(98, 203, 129, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: rgba(98, 203, 129, 1)">工号：${row.code}</div>
                <div style="background: rgba(123, 101, 251, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: #7B65FB">${row.skill_cate_name}</div>
                <div style="flex: 1"></div>`
                if(row.is_rest == 0){
                    result  += `<div style="background: rgba(98, 203, 129, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: rgba(98, 203, 129, 1)">${row.is_rest_text}</div>`
                }else{
                     result  += `<div style="background: #F7F7F7;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color: #666666">${row.is_rest_text}</div>`
                }
                result += `
                
            </div>
        
            <div style="color: #333333;font-size: 14px;margin-top: 8px;display: flex;align-items: center;">
                <span style="color: #333;font-size: 14px;margin-right: 8px;">${row.sex_text}</span><span style="color: #333;font-size: 14px;margin-right: 8px;">${row.mobile}</span><span>身份证：</span>${row.idcard}
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;">
                <div style="background: #F0FAF3;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">学历：</span>${row.edu_text}</div>
                <div style="background: #EFF5FF;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">年龄：</span>${row.age}</div>
                <div style="background: #F6F1FF;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-right: 8px;"><span style="color: #999999">民族：</span>${row.nation}</div>
                <div style="background: #FFF7E6;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;"><span style="color: #999999">经验：</span>${row.exper_text}</div>
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;width: 100%;">
                <div style="width: 100%;background: #F7F7F7;display: flex;align-items: center;padding: 8px;border-radius: 6px;"><span style="color: #999999">所在位置：</span>${row.province}${row.city}${row.district}${row.address}</div>
            </div>
            <div style="display: flex;align-items: center;margin-top: 8px;width: 100%;">
                <div style="width: 100%;background: #EFF5FF;display: flex;align-items: center;padding: 8px;border-radius: 6px;color: #1677FF;"><span style="color: #999999">所属商户：</span>${row.shop_name}</div>
            </div>
        </div>
    </div>`
                            return  result
                        }},
                        {field: 'id', title: __('钱包'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
                            return `
                            <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">保证金</span>
        <span style="color: #62CB81;font-size: 14px;">${row.ensure_price}</span>
    </div>
                           <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">平台钱包</span>
        <span style="color: #62CB81;font-size: 14px;">${row.skillmoney.money}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">商户钱包</span>
        <span style="color: #62CB81;font-size: 14px;">${row.skillmoney.shop_money}</span>
    </div>
    
                            `
                        }},
                        {field: 'id', title: __('接单信息'),operate: false,formatter:function (value,row){
                            return `
                            <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">每日可接单数量</span>
        <span style="color: #333;font-size: 14px;">${row.accept_nums}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">已接单数量</span>
        <span style="color: #333;font-size: 14px;">${row.already_accept_nums}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">订单收益分成%</span>
        <span style="color: #333;font-size: 14px;">${row.percent}</span>
    </div>
                            `
                        }},
                        {field: 'id', title: __('证件'),operate: false,formatter:function (value,row){
                            return `
                           <div style="display: flex;align-items: center;border-bottom: 1px solid #EEEEEE; padding: 10px 0;">
        <div style="display: flex;flex-direction: column;align-items: center;margin-right: 10px;">
            <img src="${row.front_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">身份证正面</span>
        </div>
        <div style="display: flex;flex-direction: column;align-items: center;">
            <img src="${row.opposite_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">身份证反面</span>
        </div>
    </div>
    <div style="display: flex;align-items: center;padding: 10px 0 0;">
        <div style="display: flex;flex-direction: column;align-items: center;margin-right: 10px;">
            <img src="${row.certificate_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">从业资格证</span>
        </div>
        <div style="display: flex;flex-direction: column;align-items: center;">
            <img src="${row.health_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;margin-bottom: 8px;">
            <span style="color: #999999;font-size: 12px;">健康证</span>
        </div>
    </div>
                            `
                        }},
                        {field: 'id', title: __('照片'),operate: false,cellStyle: function () {return {css: {"min-width": "300px","max-width": "500px"}}},formatter:function (value,row){
                            let word = row.goodsname.split(',')
                            let result = '<div style="color: #333;font-size: 14px;margin-bottom: 8px;flex-wrap: wrap;display: flex;align-items: center">';
                            for(let i=0; i < word.length; i++){
                                result += `<div style="margin: 0 8px 8px;">${word[i]}</div>`
                            }
                            result+='</div>'
                            return result
                        }},
                        {field: 'id', title: __('照片'),operate: false,formatter:function (value,row){
                            let images = row.images.split(',')
                            let result = `<div style="display: flex;align-items: flex-start;flex-direction: column;border-bottom: 1px solid #EEEEEE; padding: 10px 0;">
                           <span style="color: #999999;font-size: 12px;">实拍照</span>
        <div style="display: flex;flex-direction: column;align-items: center;margin-top: 8px;">
            
            <img src="${row.user_image}" alt="" style="width: 56px;height: 56px;border-radius: 8px;">
            
        </div>

    </div>`
    if(row.images.length>0){
        result+=`<div style="display: flex;align-items: flex-start;flex-direction: column;padding: 10px 0 0;margin-top: 8px;">
        <span style="color: #999999;font-size: 12px;">相册</span>
        <div style="display: flex;align-items: center;margin-top: 8px;">`;
        for(let i=0; i < images.length; i++){
                                result += `<img src="${images[i]}" alt="" style="width: 56px;height: 56px;margin-right:5px;border-radius: 8px;">`
                            }
                            result+='</div></div>'
    }
                            return  result
                        }},
                        {field: 'id', title: __('权重、状态'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
                            return `
                           
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
        <span style="font-size: 14px;color: #999;">权重</span>
        <span style="color: #333;font-size: 14px;">${row.weigh}</span>
    </div>
    <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
        <span style="font-size: 14px;color: #999;">状态</span>
        <span style="color: #1677FF;font-size: 14px;">${row.state_text}</span>
    </div>
                            `
                        }},
                         {field: 'id', title: __('时间'),operate: false, cellStyle: function () {return {css: {"min-width": "180px"}}},formatter:function (value,row){
                            return `
                           <div style="margin-bottom: 10px;">
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">创建时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.create_time}</div>
    </div>
    <div>
        <div style="color: #999999;font-size: 14px;margin-bottom: 8px;text-align:left;">更新时间</div>
        <div style="color: #333333;font-size: 14px;text-align:left;">${row.update_time}</div>
    </div>
                            `
                        }},
                        {field: 'id', title: __('Id'),visible: false},
                        {field: 'user_id', title: __('User_id'),visible: false},
                        {field: 'shop_id', title: __('Shop_id'),visible: false},
                        {field: 'shop_name', title: __('Shop_name'),operate:false,visible: false},
                        {field: 'ensure_price', title: __('Ensure_price'), operate:'BETWEEN',visible: false},
                        {field: 'code', title: __('Code'),visible: false},
                        {field: 'skillmoney.money', title: __('Money'),operate: false,visible: false},
                        {field: 'skillmoney.shop_money', title: __('Shop_money'),operate: false,visible: false},
                        {field: 'mobile', title: __('Mobile'),visible: false},
                        {field: 'accept_nums', title: __('Accept_nums'),visible: false},
                        {field: 'already_accept_nums', title: __('Already_accept_nums'),visible: false},
                        {field: 'percent', title: __('Percent'),visible: false},
                        {field: 'name', title: __('Name'),visible: false},
                        {field: 'sex', title: __('Sex'), searchList: {"1":__('Sex 1'),"0":__('Sex 0')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'idcard', title: __('Idcard'),visible: false},
                        {field: 'front_image', title: __('Front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'opposite_image', title: __('Opposite_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'user_image', title: __('User_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'certificate_image', title: __('Certificate_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'health_image', title: __('Health_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'category_id', title: __('Category_id'),visible: false},
                        {field: 'category_name', title: __('Category_name'),operate:false,visible: false},
                        {field: 'skill_cate_id', title: __('Skill_cate_id'),visible: false},
                        {field: 'skill_cate_name', title: __('Skill_cate_name'),operate:false,visible: false},
                        {field: 'goods_ids', title: __('Goods_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,visible: false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images,visible: false},
                        {field: 'edu', title: __('Edu'), searchList: {"0":__('Edu 0'),"1":__('Edu 1'),"2":__('Edu 2'),"3":__('Edu 3'),"4":__('Edu 4'),"5":__('Edu 5'),"6":__('Edu 6')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'age', title: __('Age'),visible: false},
                        {field: 'nation', title: __('Nation'),visible: false},
                        {field: 'exper', title: __('Exper'), searchList: {"0":__('Exper 0'),"1":__('Exper 1'),"2":__('Exper 2'),"3":__('Exper 3')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'province', title: __('Province'), operate: 'LIKE',visible: false},
                        {field: 'city', title: __('City'), operate: 'LIKE',visible: false},
                        {field: 'district', title: __('District'), operate: 'LIKE',visible: false},
                        {field: 'address', title: __('Address'), operate: 'LIKE',visible: false},
                        {field: 'is_rest', title: __('Is_rest'), searchList: {"0":__('Is_rest 0'),"1":__('Is_rest 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'rebate_price', title: __('Rebate_price'), operate:'BETWEEN',visible: false},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1')}, formatter: Table.api.formatter.normal,visible: false},
                        {field: 'weigh', title: __('Weigh'), operate: false,visible: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'list',
                                    text: __('平台余额明细'),
                                    title: __('平台余额明细'),
                                    classname: 'btn btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/money/serviceusermoneylog/index?user_id='+row.user_id;
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('商户余额明细'),
                                    title: __('商户余额明细'),
                                    classname: 'btn btn-xs btn-change btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/money/shopmoneylog/index?user_id='+row.user_id;
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('保证金明细'),
                                    title: __('保证金明细'),
                                    classname: 'btn btn-xs btn-list btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/money/ensurelog/index?user_id='+row.user_id+'&type=0';
                                    },
                                },
                                {
                                    name: 'list',
                                    text: __('订单列表'),
                                    title: __('订单列表'),
                                    classname: 'btn btn-xs btn-list btn-success btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: function(row){
                                        return 'service/order/order/index?user_id='+row.id;
                                    },
                                },
                                {
                                    name: 'info',
                                    text: __('扣除保证金'),
                                    title: __('扣除保证金'),
                                    classname: 'btn btn-xs btn-list btn-danger btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: 'service/skill/skill/deduct',
                                },
                                {
                                    name: 'edit',
                                    text: __('编辑'),
                                    title: __('编辑'),
                                    classname: 'btn btn-xs btn-status btn-dialog',
                                    icon: 'fa fa-list-o',
                                    url: 'service/skill/skill/edit',
                                }
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'service/skill/skill/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'service/skill/skill/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'service/skill/skill/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            $("[data-toggle='addresspicker']").data("callback", function(res){
             //其中res则是包含了address/lat/lng/zoom等信息的JSON对象
             console.log(res)
            });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
